package com.back.system.service.impl;

import com.back.common.api.vo.Result;
import com.back.system.entity.SysUser;
import com.back.system.mapper.SysUserMapper;
import com.back.system.service.SysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public Result<?> getSysUserById(String id) {

        log.info("根据id查询系统用户，id：{}", id);

        SysUser sysUser = sysUserMapper.getSysUserById(id);

        return Result.ok(sysUser);
    }

    @Override
    public Result<?> getSysUserList(Integer pageNo, Integer pageSize) {

        log.info("系统用户分页列表查询，页码：{}，页数：{}", pageNo, pageSize);

        // 解决分页时，pageNo = 1, 返回的数据结果会跳过第一条数据
        Integer offset = (pageNo - 1) * pageSize;

        List<SysUser> userList = sysUserMapper.getSysUserList(offset, pageSize);

        return Result.ok(userList);
    }
}
